import 'package:common_utils/common_utils.dart';
import 'package:intl/intl.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/generated/l10n.dart';

String formatDate(int time) {
  var timeMs = time * 1000;
  // var now = DateTime.now().millisecondsSinceEpoch;
  // var space = now - timeMs;
  // if (space < 60 * 1000){
  //   var sec = space / 1000;
  //   return "${sec.toInt()}秒前";
  // }else if (space < 60 * 60 * 1000) {
  //   var min = space / (60 * 1000);
  //   return "${min.toInt()}分钟前";
  // } else if (space < 24 * 60 * 60 * 1000) {
  //   var hour = space / (60 * 60 * 1000);
  //   return "${hour.toInt()}小时前";
  // }
  if (DateUtil.isToday(timeMs)) {
    return DateUtil.formatDateMs(timeMs, format: "HH:mm");
  }
  // if (DateUtil.isYesterday(
  //     DateTime.fromMillisecondsSinceEpoch(timeMs), DateTime.now())) {
  //   return '昨日';
  // }

  // if (DateUtil.yearIsEqualByMs(timeMs, DateTime.now().millisecondsSinceEpoch)) {
  //   return DateUtil.formatDateMs(timeMs, format: 'MM/dd');
  // }
  return DateUtil.formatDateMs(timeMs, format: DateFormats.y_mo_d);
}

String enFormatDate(int time) {
  var timeMs = time * 1000;
  if (DateUtil.isToday(timeMs)) {
    return DateUtil.formatDateMs(timeMs, format: "HH:mm");
  }
  return DateUtil.formatDateMs(timeMs, format: 'dd/MM/yyyy');
}

String homeDormatDate(int time) {
  if ((appContext.storage.getString("storyLocal") ?? Intl.getCurrentLocale())
      .contains('zh')) {
    DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(time);
    return DateUtil.formatDate(dateTime, format: 'yyyy年MM月dd日');
  }
  return '';
}

String greeting() {
  var hour = DateTime.now().hour;
  if (hour < 12) {
    return S().morning;
  }
  if (hour < 17) {
    return S().afternoon;
  }
  return S().evening;
}
